<?php

namespace app\common\model;

use think\Model;

class Service extends Model
{
    protected $name = 'service';
    
    protected $autoWriteTimestamp = 'int';

    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    protected $append = [
        'status_text',
        'is_recommend_text'
    ];
    
    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getIsRecommendList()
    {
        return ['0' => __('No'), '1' => __('Yes')];
    }

    public function getIsRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
        $list = $this->getIsRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function teachers()
    {
        return $this->belongsToMany('User', 'service_teacher', 'teacher_id', 'service_id');
    }
}